package yunpian

import (
	"errors"
	"fmt"

	"github.com/yunpian/yunpian-go-sdk/sdk"
)

// Client 云片sms客户端
type Client struct {
	client sdk.YunpianClient
}

// NewClient creates a new yunpian sms client.
func NewClient(apiKey string) Client {
	return Client{
		client: sdk.New(apiKey),
	}
}

// SendSingle sends the content to sigle mobile.
func (c Client) SendSingle(mobile, content string) error {
	param := sdk.NewParam(2)
	param[sdk.MOBILE] = mobile
	param[sdk.TEXT] = content
	r := c.client.Sms().SingleSend(param)
	//var res  SingleSendResponse
	if r == nil {
		return errors.New("未获取到【云片】任何响应")
	}
	if r.Code != 0 {
		return fmt.Errorf("发送失败,code:%d,msg:%s,detail:%s", r.Code, r.Msg, r.Detail)
	}
	// res=SingleSendResponse{
	// 	Count: r,
	// }
	return nil
}
